﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Model.Group;

namespace YouHP.Pages
{
    // 此为展示某个医生开具的中药方的页面，要显示所有的正在服用该医生开具中药方的用户
    public class Doctor : BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if(ErrorCount > 0) return;
            
            HandleCommon();
            if(ErrorCount > 0) return;
            
            if(IsPost) HandlePost();
            else HandleGet();
        }

        protected DoctorInfo _doctorInfo;
        protected List<PrescriptionInfo> _prescriptionList;

        protected int _recordCount = 0;
        protected int _pageCount = 0;
        protected int _pageSize = 8;
        protected int _pageIndex = 1;
        protected string _pagingString;

        protected void HandleCommon()
        {
            int doctorId = RequestTools.GetQueryInt("doctorid", 0);
            if (doctorId <= 0)
            {
                Response.Write("找不到该医生");
                return;
            }

            _doctorInfo = DoctorBLL.Instance.GetDoctorInfo(doctorId);
            if (_doctorInfo.Id <= 0)
            {
                Response.Write("找不到该医生");
                return;
            }

            bool userLogin = UserData != null && UserData.Id > 0;
            if (userLogin == false)
            {
                this.AddLocation("中药列表", "/PrescriptionAll.aspx");
                
            }

            string diseaseName = DiseaseBLL.Instance.GetDiseaseInfo(_doctorInfo.DiseaseId).Name;
            this.AddLocation("<font color=\"red\">" + diseaseName + "</font>" + "&nbsp;中药列表", 
                string.Format("/DoctorList.aspx?diseaseid={0}", _doctorInfo.DiseaseId));

            this.AddLocation(string.Format("{0}", _doctorInfo.Name), "");

            // Title of this page
            this.SetTitle(string.Format("{0} 中药列表", _doctorInfo.Name));
        }
        
        protected void HandlePost()
        {
            
        }

        protected void HandleGet()
        {
            _pageIndex = RequestTools.GetQueryInt("page", 1);

            _prescriptionList = DoctorBLL.Instance.GetDoctorPrescriptionList(_doctorInfo.Id);
            if (_prescriptionList == null || _prescriptionList.Count == 0)
            {
                Response.Write("该医生暂无药方");
                return;
            }

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");
            _pageCount = Utils.GetPageCount(_recordCount, _pageSize);
            _pagingString = this.GetPagingString(_pageIndex, _pageCount, "/Doctor.aspx" + query, "page");

        }   // HandleGet

    }   
}